// document.documentElement.style.transform = "scale(1.5)";
const signInBtn = document.getElementById("signIn");
const signUpBtn = document.getElementById("signUp");
const container = document.querySelector(".container");

signInBtn.addEventListener("click", () => {
    container.classList.remove("panel-active");
});

signUpBtn.addEventListener("click", () => {
    container.classList.add("panel-active");
});
const card = document.getElementById('card');
const cardImage = document.getElementById('cardImage');

card.addEventListener('click', function () {
    card.classList.toggle('flipped');
    if (card.classList.contains('flipped')) {
        cardImage.src = 'your-new-image.jpg';
    } else {
        cardImage.src = '';
    }
});
let lastPopupTime = 0; // 上次弹窗时间
let lastPopupTime2 = 0; // 上次弹窗时间

let RandomVerificationCode;
let RegisterRandomVerificationCode;

// 生成6位随机验证码
function generateRandomCode() {
    let code = '';
    const characters = '0123456789';
    for (let i = 0; i < 6; i++) {
        const randomIndex = Math.floor(Math.random() * characters.length);
        code += characters.charAt(randomIndex);
    }
    return code;
}

// 复制验证码到剪贴板
function copyCodeToClipboard(code) {
    const textArea = document.createElement("textarea");
    textArea.value = code;
    document.body.appendChild(textArea);
    textArea.select();
    document.execCommand('copy');
    document.body.removeChild(textArea);
}

// 显示验证码弹窗
function showCodePopup() {
    const phoneNumber = document.getElementById('phoneNumber3').value; // 获取手机号输入框的值
    if (!phoneNumber) {
        alert('请输入手机号以获取验证码。');
        return;
    }
    const currentTime = Date.now(); // 当前时间
    let count = 0;
    if (currentTime - lastPopupTime >= 60000) { // 检查是否已经过去60秒
        const generatedCode = generateRandomCode();
        const popupMessage = '验证码: ' + generatedCode;
        RandomVerificationCode = generatedCode;
        // 创建弹窗
        const confirmation = confirm(popupMessage + "\n\n点击确定将验证码复制到剪贴板。");

        if (confirmation) {
            copyCodeToClipboard(generatedCode); // 复制验证码
        }

        lastPopupTime = currentTime; // 更新上次弹窗时间
    } else {
        if (count.equals(0)) {
            alert('请等待60秒后再次获取验证码。');
            count = 1
        }
    }
}

function RegisterShowCodePopup() {
    const phoneNumber = document.getElementById('phoneNumber').value; // 获取手机号输入框的值
    if (!phoneNumber) {
        alert('请输入手机号以获取验证码。');
        return;
    }
    const currentTime = Date.now(); // 当前时间
    let count = 0;
    if (currentTime - lastPopupTime2 >= 60000) { // 检查是否已经过去60秒
        const generatedCode = generateRandomCode();
        const popupMessage = '验证码: ' + generatedCode;
        RegisterRandomVerificationCode = generatedCode;
        // 创建弹窗
        const confirmation = confirm(popupMessage + "\n\n点击确定将验证码复制到剪贴板。");

        if (confirmation) {
            copyCodeToClipboard(generatedCode); // 复制验证码
        }
        lastPopupTime2 = currentTime; // 更新上次弹窗时间
    } else {
        if (count.equals(0)) {
            alert('请等待60秒后再次获取验证码。');
            count = 1
        }
    }
}

function clearForm() {
    document.getElementById('phoneNumber2').value = '';
    document.getElementById('password2').value = '';

    document.getElementById('username').value = '';
    document.getElementById('phoneNumber').value = '';
    document.getElementById('password').value = '';
}

window.onload = function () {
    const greetingElement = document.getElementById("greeting")
    const greetings = [{text: "Hello", color: "rgb(0,159,255)"},
        {text: "你好", color: "rgb(255,0,6)"},
        {text: "привет", color: "green"},
        {text: "Bonjour", color: "orange"},
        {text: "Hallo", color: "purple"},
        {text: "こんにちは", color: "pink"},
        {text: "Hola", color: "brown"},
        {text: "Здравствуйте", color: "gray"},
        {text: "नमस्ते", color: "teal"},
        {text: "안녕하세요", color: "violet"},
        {text: "Ciao", color: "gold"},];
    let currentGreetingIndex = 0

    function changeGreeting() {
        greetingElement.style.opacity = "0"
        setTimeout(function () {
            greetingElement.textContent = greetings[currentGreetingIndex].text
            greetingElement.webkitTextStroke = greetings[currentGreetingIndex].color
            greetingElement.style.opacity = "1"
            currentGreetingIndex = (currentGreetingIndex + 1) % greetings.length
        }, 500)
    }

    changeGreeting()
    setInterval(changeGreeting, 2000)
}

function RegisterSubmitForm() {
    document.getElementById('generatedCode2').value = RegisterRandomVerificationCode;
    document.submit();
}

function submitForm() {
    document.getElementById('generatedCode').value = RandomVerificationCode;
    document.submit();
}
